
import { log } from 'cc';
import Notification from '../../lib/mvp/Notification';
import { Presenter } from '../../lib/mvp/Presenter';
import { LoginProxy } from './LoginProxy';
import { LoginView } from './LoginView';
import Facade from '../../lib/mvp/Facade';
import { winMgr } from '../../tool/WinMgr';
import { Dir } from '../../tool/Dir';


export class LoginPresenter extends Presenter {

    //事件名称
    static PRESENTER_OK = "PRESENTER_OK";

    public handleNotification(notification: Notification): void {
        if (notification.getName() == LoginView.LOGINVIEW_OK) {
            this.onEvent_Login(notification);
        }
        else {

        }
    }

    //event注册
    public listNotificationInterests(): string[] {
        let list: Array<string> = [
            LoginView.LOGINVIEW_OK,
            LoginView.LOGINVIEW_Cancel,
        ];
        return list;
    }

    /*********************事件响应*****************/
    onEvent_Login(notification: Notification) {
        let data = notification.getBody();
        log(data);
        let loginPorxy = this.getProxy("LoginProxy") as LoginProxy;
        loginPorxy.userName = data["name"];
        log(loginPorxy.userName);

        this.onNet_Login();

    }


    /*********************网络事件响应*****************/
    onNet_Login() {

        this.sendNotification(LoginView.LOGINVIEW_CLOSE);

        winMgr.showWin(Dir.getWin("Layout_Main"));
    }


}


